<?php
/**
 * Plugin Name: TT-Statustuj
 * Plugin URI: http://www.tt-statistik.de
 * Description: A widget that displays the next game of a table tennis club.
 * Version: 1.0
 * Author: Fabian Kajzar
 */

/**
 * Add function to widgets_init that'll load our widget.
 * @since 1.0
 */
add_action( 'widgets_init', 'load_tt_statistik_widgets' );

/**
 * Register our widget.
 * 'Example_Widget' is the widget class used below.
 *
 * @since 1.0
 */
function load_tt_statistik_widgets() {
	register_widget( 'TT_Statistik_Next_Game' );
}

/**
 * TT_Statistik_Next_Game class.
 * @since 1.0
 */
class TT_Statistik_Next_Game extends WP_Widget {

	/**
	 * Widget setup.
	 */
	function TT_Statistik_Next_Game() {
		/* Widget settings. */
		$widget_ops = array( 'classname' => 'TT_Statistik_Next_Game', 'description' => __('An widget that displays the next game of a table tennis club.', 'TT_Statistik_Next_Game') );

		/* Widget control settings. */
		$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'tt-statistik-next-game' );

		/* Create the widget. */
		$this->WP_Widget( 'tt-statistik-next-game', __('TT-Statistik Next Game', 'TT_Statistik_Next_Game'), $widget_ops, $control_ops );
	}

	/**
	 * How to display the widget on the screen.
	 */
	function widget( $args, $instance ) {
		extract( $args );

		/* Our variables from the widget settings. */
		$title = apply_filters('widget_title', $instance['title'] );

		/* Before widget (defined by themes). */
		echo $before_widget;

		/* Display the widget title if one was input (before and after defined by themes). */
		if ( $title )
			echo $before_title . $title . $after_title;
			
		echo "Das ist mein erstes WP Widget :)";


		/* After widget (defined by themes). */
		echo $after_widget;
	}

	/**
	 * Update the widget settings.
	 */
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		/* Strip tags for title and name to remove HTML (important for text inputs). */
		$instance['title'] = strip_tags( $new_instance['title'] );

		return $instance;
	}

	/**
	 * Displays the widget settings controls on the widget panel.
	 * Make use of the get_field_id() and get_field_name() function
	 * when creating your form elements. This handles the confusing stuff.
	 */
	function form( $instance ) {

		/* Set up some default widget settings. */
		$defaults = array( 'title' => __('Example', 'example'));
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>

		<!-- Widget Title: Text Input -->
		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
		</p>

	<?php
	}
}

?>